//
//  LookAlreadyTaskViewController.swift
//  BusinessIOS
//
//  Created by Rain on 2018/12/28.
//  Copyright © 2018 XingJian Li. All rights reserved.
//

import UIKit
import Alamofire
class LookAlreadyTaskViewController: UIViewController {
    var tableView   : UITableView!

    var LookAlreadyTaskArray = [LookAlreadyTaskModel]()
    var numIdString : String!
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = bgGrayColor;
        navigationItem.title="查看进度"
        
        tableView = UITableView(frame:self.view.frame, style:.plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.showsHorizontalScrollIndicator = false
        tableView.showsVerticalScrollIndicator = false
        
        tableView.tableFooterView = UIView.init()
        
        
        tableView.register(NSClassFromString("LookAlreadyTaskTableViewCell"), forCellReuseIdentifier: "LookAlreadyTaskTableViewCell")
        
        
        view.addSubview(tableView)
        tableView.sd_layout()?.spaceToSuperView(UIEdgeInsets.zero)
        
        
        self.taskData()
    }
    
    //我的待办
    func taskData(){
        

        let urlString = "http://wwwqjzsyzcscom.aykj.net.cn/api/activiti/activitiOperationLog/manage"
        
        let json = "{\"informationRecordId\":\"\(self.numIdString!)\"}"
        
        let url = URL(string: urlString)!
        let jsonData = json.data(using: .utf8, allowLossyConversion: false)!
        var request = URLRequest(url: url)
        request.httpMethod = HTTPMethod.post.rawValue
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = jsonData
        
        Alamofire.request(request).responseJSON {
            (response) in
            print("jindu====\(response)")
           
            if response.result.isSuccess {
                let json = JSON(response.data!)
                
                let array  = json["resultData"].array;
                
                for dataDic in  array!
                {
                    let model =   LookAlreadyTaskModel()
                    
                    model.assigneeName = dataDic["assigneeName"].string
                    model.deploymentName = dataDic["deploymentName"].string
                    model.endTime = dataDic["endTime"].string
                    model.opinion = dataDic["projeopinionctNum"].string
                    model.startTime = dataDic["startTime"].string
                    model.taskName = dataDic["taskName"].string
                    model.taskResult = dataDic["taskResult"].string
                    model.toLoginName = dataDic["toLoginName"].string
                    self.LookAlreadyTaskArray.append(model)
                    
                }
                
                
                self.tableView.reloadData()
                
                
            }
                
        }
 
            
    }
        



}
extension LookAlreadyTaskViewController: UITableViewDelegate, UITableViewDataSource {
    
    
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.LookAlreadyTaskArray.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 50
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
           let LookAlreadyModel:LookAlreadyTaskModel = self.LookAlreadyTaskArray[indexPath.row]
        
        let cell = LookAlreadyTaskTableViewCell(style:UITableViewCellStyle.default, reuseIdentifier: "LookAlreadyTaskTableViewCell")
        
        cell.LookAlreadyTaskTableViewCell(model: LookAlreadyModel)
        cell.selectionStyle = UITableViewCellSelectionStyle.none
    
        return cell
    }
    

    
}
